<?php
namespace app\Job;

use think\queue\Job;
use think\Db;
use think\facade\Log;
use think\facade\Cache;
use app\services\OrderCount;

use app\services\MqInsertService;

class DelayedDateOrder{
    public function fire(Job $job, $data){
        //生成报表
        $OrderCount = new OrderCount;

        try {

            $reslut = $OrderCount->fireDate($data);
        } catch (\Exception $e) {
            trace('错误结果：'.$e->getMessage());
        }

        //计算下次生成时间
        $unixtime = strtotime(date('Y-m-d 00:10:00',strtotime("+1 day")));
        $nexttime = $unixtime - time();


        //加入定时器
        $mqinsert = new MqInsertService('sendtask','app\Job\DelayedDateOrder');
        $mqinsertReslut = $mqinsert->addLaterJob(['ordertime'=>date('Y-m-d H:i:s') ],$nexttime);

        trace('报表生成结果：'.$reslut.'下次生成时间：'.date("Y-m-d H:i:s",$unixtime).'['.$nexttime.'秒后]'.$mqinsertReslut);

        //重启
        $job->delete();
        // $job->release($nexttime);

    }
}